//
//  LHQDestinationBeautyTripViewController.m
//  God_is_a_Girl
//
//  Created by dllo on 15/9/28.
//  Copyright (c) 2015年 呸. All rights reserved.
//

#import "LHQDestinationBeautyTripViewController.h"
#import "LHQDestinationBeautyTripDetailModel.h"
#import "LHQDestinationBeautytripDetailTableViewCell.h"
#import <AFNetworking.h>
#import "LJP_ DetailsViewController.h"
@interface LHQDestinationBeautyTripViewController () <UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,retain) NSMutableArray  *arr;//接收数据

@property (nonatomic,retain) UITableView  *tableView;

@property (nonatomic,retain) LHQDestinationBeautyTripDetailModel *model;

@end

@implementation LHQDestinationBeautyTripViewController

- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBarHidden = NO;

}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    [self  datahandel];

}

-(void)tableViewSubView
{
    self.tableView = [[UITableView  alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
   
    
}
-(void)datahandel
{
    self.arr = [NSMutableArray  array];
    
    AFHTTPRequestOperationManager  *manager = [AFHTTPRequestOperationManager   manager];
    
    manager.responseSerializer.acceptableContentTypes = [NSSet  setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html",nil];//支持所有接口类型
    
    NSString *str = [NSString stringWithFormat:@"http://api.breadtrip.com/destination/place/%@/%@/trips/?start=0&count=20",self.type,self.idStr];//id是字母
    NSLog(@"%@", str);
    [manager  GET:str parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSArray *arr = [responseObject objectForKey:@"items"];
        self.arr = arr.mutableCopy;
        [self.tableView  reloadData];
        [self  tableViewSubView];
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
    
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
    
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.arr.count;
    
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    self.model = [[LHQDestinationBeautyTripDetailModel  alloc] init];
    
    NSDictionary  *dic = [self.arr  objectAtIndex:indexPath.row];
    
    [self.model  setValuesForKeysWithDictionary:dic];
    LHQDestinationBeautytripDetailTableViewCell *cell =  [tableView  dequeueReusableCellWithIdentifier:@"reuse"];
    if (cell == nil) {
        cell = [[LHQDestinationBeautytripDetailTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"reuse"];
    }
    cell.model = self.model;
    return cell;
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    LHQDestinationBeautyTripDetailModel *model = [[LHQDestinationBeautyTripDetailModel  alloc] init];
    
    NSDictionary  *dic = [self.arr  objectAtIndex:indexPath.row];
    [model setValue:dic[@"id"] forKey:@"tripId"];
    LJP__DetailsViewController *details = [[LJP__DetailsViewController alloc] init];
    details.stringId = model.tripId.stringValue;
    [self.navigationController pushViewController:details animated:YES];
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 200;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
